//: Playground - noun: a place where people can play

import UIKit

//常量的声明
let str = "constant"
//变量的声明
var vStr = "variable"
//类型注解
var typeNote:String
//全局输出函数
print(vStr)
//拼接输出
print("This is\(vStr)")
//整数

let minValue = UInt8.min
let maxValue = UInt8.max
let intMin = Int.min
let intMax = Int.max

//十进制
let decimalInteger = 17
//二进制
let binaryInteger = 0b10001 // 17 in binary notation
//八进制
let octalInteger = 0o21 // 17 in octal notation
//十六进制
let hexadecimalInteger = 0x11 // 17 inhexadecimal notation

//整数和浮点型的转换
let three = 3
let pointNum = 0.14159
//let pai = three + pointNum 会报错
var pi = Double(three) + pointNum
var intPi = Int(pi)
pi = 3.6
intPi = Int(pi)

//类型别名
typealias AudioSample = UInt8
var IntEeightMax = AudioSample.max
//布尔类型
let right = true
let failuer = false


/**
*  元组类型
*/
//元组类型可以将一些不同的数据类型组装成一个元素，这些数据类型可以是任意类型，并且不需要是同样的类型

let http404Error = (404,"Not Found")
print("\(http404Error.0)")
print("\(http404Error.1)")
let (statusCode, statusMessage) = http404Error
print("\(statusCode)")
print("\(statusMessage)")
//如果仅需要元组中的个别值，可以使用(_)来忽略不需要的值
let (justCode,_) = http404Error
justCode
//在创建一个元组的时候，也可以直接指定每个元素的名称，然后直接使用元组名.元素名访问
let http200Status = (sCode:200,description:"ok")
http200Status.sCode
http200Status.description
http200Status.0
http200Status.1

//可选类型

let possibleNumber = "123"
var possibleStr = "qad"
var convertedNumber = Int(possibleNumber)
 convertedNumber = Int(possibleStr)

//隐式解包可选类型
//隐式解包的可选类型主要用在一个变量/常量在定义瞬间完成之后值一定会存在的情况
let possibleString: String? = "An optional string."
print(possibleString!) // requires an exclamation mark to access its value
// prints "An optional string."

let assumedString: String! = "An implicitly unwrapped optional string."
print(assumedString) // no exclamation mark is needed to access its value
// prints "An implicitly unwrapped optional string."

//使用断言调试
let age = 3
assert(age>=0,"A person's age cannot be less than zero")







